﻿@using NetCoreCMS.Models;
@using NetCoreCMS.Common;
@{
    Layout = "~/Areas/admin/Views/Shared/_LayoutEdit.cshtml";
    ViewBag.Title = "编辑内容";
    Sysconfig sysConfig = ViewData["config"] as Sysconfig;
    List<SelectListItem> categoryList = ViewData["categoryList"] as List<SelectListItem>;
    List<SelectListItem> shopList = ViewData["shopList"] as List<SelectListItem>;
    Article m = ViewData["model"] as Article;
     int channel_id = int.Parse(ViewBag.ChannelId as string);
}
@section HeaderContent{
    <script src="~/editor/ueditor.config.js"></script>
    <script src="~/editor/ueditor.all.min.js"></script>
    <script src="~/editor/lang/zh-cn/zh-cn.js"></script>
    <script>
   var artId = Number(@ViewBag.Id);
   $(function () {
      //初始化表单验证
      $("#form1").initValidform();

      //初始化编辑器
      $(".editor").each(function (i) {
         var objId = $(this).attr("id");
         if (objId != "undefined") {
            var editor = UE.getEditor(objId, {
               serverUrl: '/upload_ajax/index',
               initialFrameWidth: '100%',
               initialFrameHeight: 350
            });
         }
      });
      $(".editor-mini").each(function (i) {
         var objId = $(this).attr("id");
         if (objId != "undefined") {
            var editorMini = UE.getEditor(objId, {
               serverUrl: '/upload_ajax/index',
               initialFrameWidth: '100%',
               initialFrameHeight: 250,
               toolbars: [[
                   'fullscreen', 'source', '|', 'undo', 'redo', '|',
                   'bold', 'italic', 'underline', 'strikethrough', 'removeformat', 'pasteplain', '|', 'forecolor', 'insertorderedlist', 'insertunorderedlist', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
                'link', 'unlink', 'anchor', '|',
                'simpleupload', 'insertimage', 'scrawl', 'insertvideo'
               ]]
            });
         }
      });



      //初始化上传控件
      $(".upload-img").InitUploader({ filesize: "@sysConfig.imgsize", sendurl: "/upload_ajax/index", swf: "/scripts/webuploader/uploader.swf", filetypes: "@sysConfig.fileextension" });
      $(".upload-album").InitUploader({ btntext: "批量上传", multiple: true, water: true, thumbnail: true, filesize: "@sysConfig.imgsize", sendurl: "/upload_ajax/index", swf: "/scripts/webuploader/uploader.swf" });

      //设置封面图片的样式
      $(".photo-list ul li .img-box img").each(function () {
         if ($(this).attr("src") == $("#hidFocusPhoto").val()) {
            $(this).parent().addClass("selected");
         }
      });

      //创建上传附件
      $(".attach-btn").click(function () {
         showAttachDialog();
      });

      //创建商品规格
      $(".spec-btn").click(function () {
         showSpecDialog();
      });

      //赋值规格市场价格
      $("#field_control_market_price").blur(function () {
         $("#div_spec__container").find("input[name='spec_market_price']").val($(this).val());
      });
      //赋值规格销售价格
      $("#field_control_sell_price").blur(function () {
         $("#div_spec__container").find("input[name='spec_sell_price']").val($(this).val());
      });
   });

   //初始化规格窗口
   function showSpecDialog() {
      var d = top.dialog({
         id: 'specDialogId',
         padding: 0,
         title: "商品规格",
         url: '/admin/dialog_article_spec/index'
      }).showModal();
      //将容器对象传进去
      d.data = $("#item_box");
   }
   //初始化会员组价格窗口
   function showPriceDialog(obj) {
      var d = top.dialog({
         padding: 0,
         title: "会员组价格",
         url: '/admin/dialog_group_price/index',
         width: 500
      }).showModal();
      //将对象传进去
      d.data = obj;
   }
   //计算出最小的市场价格
   function countMarketPrice(obj) {
      var objName = $(obj).attr("name");
      var minValue = parseFloat($(obj).val());
      $("input[name='" + objName + "']").each(function () {
         if ($(this).val().length > 0) {
            if (parseFloat($(this).val()) < minValue) {
               minValue = parseFloat($(this).val());
            }
         }
      });
      $("#field_control_market_price").val(minValue);
   }
   //计算最小的销售价格
   function countSellPrice(obj) {
      var objName = $(obj).attr("name");
      var minValue = parseFloat($(obj).val());
      $("input[name='" + objName + "']").each(function () {
         if ($(this).val().length > 0) {
            if (parseFloat($(this).val()) < minValue) {
               minValue = parseFloat($(this).val());
            }
         }
      });
      $("#field_control_sell_price").val(minValue);
        }
         //计算最小的PV价格
   function countPVPrice(obj) {
      var objName = $(obj).attr("name");
      var minValue = parseFloat($(obj).val());
      $("input[name='" + objName + "']").each(function () {
         if ($(this).val().length > 0) {
            if (parseFloat($(this).val()) < minValue) {
               minValue = parseFloat($(this).val());
            }
         }
      });
      $("#field_control_pv_price").val(minValue);
   }
   //计算库存总数量
   function countStockQuantity(obj) {
      var objName = $(obj).attr("name");
      var countValue = 0;
      $("input[name='" + objName + "']").each(function () {
         if ($(this).val().length > 0) {
            countValue += parseFloat($(this).val());
         }
      });
      $("#field_control_stock_quantity").val(countValue);
   }


   //设置视图样式
   function setView(viewStyle) {
      document.location = "index?action=Edit&id=@ViewBag.Id&channel_id=@ViewBag.ChannelId&category_id=@ViewBag.CategoryId&keywords=@ViewBag.Keywords&property=@ViewBag.Property&page=@ViewBag.Page&prolistview=" + viewStyle;
   }

   //批量删除
   function submitDelete() {
      var channel_id = Number(@ViewBag.ChannelId);
      var $row = $("#ltable tr:gt(0)");
      var json = { channel_id: channel_id, id: artId, list: [] };
      $($row).each(function (i, item) {
         if ($(item).find("input:checkbox").prop("checked")) {
            var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
            var obj = { id: id };
            json.list.push(obj);
         }
      });
   }

   //ExePostBack回调函数
   function __doPostBack(objId) {
      if (objId == "btnDelete") {
         submitDelete();
      }
   }

    </script>
}
<form id="form1" method="post" action="SubmitSave?action=@ViewBag.Action&id=@ViewBag.Id&channel_id=@ViewBag.ChannelId">
    <!--导航栏-->
    <div class="location">
        <a href="../article_list/index?channel_id=@ViewBag.ChannelId" class="back"><i class="iconfont icon-up"></i><span>返回列表页</span></a>
        <a href="../center/index"><i class="iconfont icon-home"></i><span>首页</span></a>
        <i class="arrow iconfont icon-arrow-right"></i>
        <a href="../article_list/index?channel_id=@ViewBag.ChannelId"><span>内容管理</span></a>
        <i class="arrow iconfont icon-arrow-right"></i>
        <span>编辑内容</span>
        <div class="clipboard">
            <span><label id="clipMess"></label></span>
            <a href="javascript:;" class="copy" onclick="copy();"><i class="iconfont icon-copy"></i><span>复制</span></a>
            <a href="javascript:;" class="paste disable" onclick="paste();"><i class="iconfont icon-log"></i><span>粘贴</span></a>
        </div>
    </div>
    <div class="line10"></div>
    <!--/导航栏-->
    <!--内容-->
    <div id="floatHead" class="content-tab-wrap">
        <div class="content-tab">
            <div class="content-tab-ul-wrap">
                <ul>
                    <li><a class="selected" href="javascript:;">基本信息</a></li>
                    <li><a href="javascript:;">详细描述</a></li>
                    <li><a href="javascript:;">SEO选项</a></li>
                </ul>
            </div>
        </div>
    </div>

    <!-- 基本信息 -->
    <div class="tab-content">
        <dl>
            <dt>供货商</dt>
            <dd>
                <div class="rule-single-select">
                    @Html.DropDownList("ddlShopId", new SelectList(shopList, "Value", "Text", m.shop_id.ToString()), new { datatype = "*", sucmsg = " " })
                </div>
            </dd>
        </dl>
        <dl>
            <dt>所属类别</dt>
            <dd>
                <div class="rule-single-select">
                    @Html.DropDownList("ddlCategoryId", new SelectList(categoryList, "Value", "Text", m.category_id.ToString()), new { datatype = "*", sucmsg = " " })
                </div>
            </dd>
        </dl>
        <dl>
            <dt>是否发布</dt>
            <dd>
                <div class="rule-single-checkbox">
                    @Html.CheckBox("cbStatus", m.status != 2, new { id = "cbStatus" })
                </div>
                <span class="Validform_checktip">*不发布前台则无法显示</span>
            </dd>
        </dl>
        <dl>
            <dt>推荐类型</dt>
            <dd>
                <div class="rule-multi-checkbox">
                    <span>
                        @Html.CheckBox("cblItem_0", m.is_msg == 1, new { id = "cblItem_0" })<label for="cblItem_0">允许评论</label>
                        @Html.CheckBox("cblItem_1", m.is_top == 1, new { id = "cblItem_1" })<label for="cblItem_1">置顶</label>
                        @Html.CheckBox("cblItem_2", m.is_red == 1, new { id = "cblItem_2" })<label for="cblItem_2">推荐</label>
                        @Html.CheckBox("cblItem_3", m.is_hot == 1, new { id = "cblItem_3" })<label for="cblItem_3">热门</label>
                        @Html.CheckBox("cblItem_4", m.is_slide == 1, new { id = "cblItem_4" })<label for="cblItem_4">幻灯片</label>
                    </span>
                </div>
            </dd>
        </dl>
        <dl>
            <dt>内容标题</dt>
            <dd>
                @Html.TextBox("txtTitle", m.title, new { @class = "input normal", datatype = "*2-100", sucmsg = " " })
                <span class="Validform_checktip">*标题最多100个字符</span>
            </dd>
        </dl>
        @if (ViewBag.ChannelId == "1")
        {
            <dl>
                <dt>调用别名</dt>
                <dd>
                    @Html.TextBox("txtCall_Index", m.call_index, new { @class = "input normal", datatype = "*0-500", sucmsg = " " })
                    <span class="Validform_checktip">仅当新闻时可用</span>
                </dd>
            </dl>
        }
        <dl>
            <dt>封面图片</dt>
            <dd>
                @{
                    //不是相册图片就绑定
                    string filename = "";
                    if (m.img_url != null)
                        filename = m.img_url.Substring(m.img_url.LastIndexOf("/") + 1);
                }
                @Html.TextBox("txtImgUrl", !filename.StartsWith("thumb_") ? m.img_url : "", new { @class = "input normal upload-path" })
                <div class="upload-box upload-img"></div>
            </dd>
        </dl>
        @if (ViewBag.ChannelId == "2")
        {
            <!-- 商品货号 -->
            <dl ID="div_goods_no">
                <dt><label id="div_goods_no_title">商品货号</label></dt>
                <dd>
                    @Html.TextBox("field_control_goods_no", m.goods_no, new { @class = "input normal", datatype = "*0-100", sucmsg = " " })
                    <label id="div_goods_no_tip" class="Validform_checktip"></label>
                </dd>
            </dl>
            <!-- /商品货号 -->
            <!-- 库存数量 -->

            <dl ID="div_stock_quantity">
                <dt><label id="div_stock_quantity_title">库存数量</label></dt>
                <dd>
                    @Html.TextBox("field_control_stock_quantity", m.stock_quantity, new { @class = "input small", datatype = "n", sucmsg = " " })
                    <label id="div_stock_quantity_tip" class="Validform_checktip"></label>
                </dd>
            </dl>
            <!-- /库存数量 -->
            <!-- 市场价格 -->
            <dl ID="div_market_price">
                <dt><label id="div_market_price_title">市场价格</label></dt>
                <dd>
                    @Html.TextBox("field_control_market_price", m.market_price, new { @class = "input small", datatype = @"/^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/", sucmsg = " " }) 元
                    <label id="div_market_price_tip" class="Validform_checktip">市场价格</label>
                </dd>
            </dl>
            <!-- /市场价格 -->
            <!-- 销售价格 -->
            <dl ID="div_sell_price">
                <dt><label id="div_sell_price_title">销售价格</label></dt>
                <dd>
                    @Html.TextBox("field_control_sell_price", m.sell_price, new { @class = "input small", datatype = @"/^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/", sucmsg = " " }) 元
                    <label id="div_sell_price_tip" class="Validform_checktip">销售价格</label>
                </dd>
            </dl>
            <!-- /销售价格 -->
            <!-- PV价格 -->
            <dl ID="div_sell_price">
                <dt><label id="div_sell_price_title">PV价格</label></dt>
                <dd>
                    @Html.TextBox("field_control_pv_price", m.pv_price, new { @class = "input small", datatype = @"/^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/", sucmsg = " " }) 元
                    <label id="div_pv_price_tip" class="Validform_checktip">PV价格</label>
                </dd>
            </dl>
            <!-- /PV价格 -->
            <!-- 积分 -->
            <dl ID="div_point">
                <dt><label id="div_point_title">积分</label></dt>
                <dd>
                    @Html.TextBox("field_control_point", m.point, new { @class = "input small", datatype = @"/^-?\d+$/", sucmsg = " " })
                    <label id="div_point_tip" class="Validform_checktip">积分</label>
                </dd>
            </dl>
            <!-- /积分 -->
            <!-- 商品规格 -->
            <dl id="div_spec__container">
                <dt>商品规格</dt>
                <dd>
                    <a class="icon-btn add spec-btn"><span>设置规格</span></a>
                    <div class="table-container" style="padding-top:10px;">
                        @Html.Hidden("hide_goods_spec_list", ViewBag.GoodsSpecJson as string)
                        <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="82%">
                            <thead>
                                <tr>
                                    <th align="center" width="15%">货号</th>
                                    <th width="8%">市场价(元)</th>
                                    <th width="8%">销售价(元)</th>
                                    <th width="8%">PV价(元)</th>
                                    <th width="8%">库存(件)</th>
                                    <th width="35%">规格</th>
                                    <th width="8%">会员价</th>
                                </tr>
                            </thead>
                            <tbody id="item_box">
                                @if (m.goods != null)
                                {
                                    foreach (Article_goods item in m.goods)
                                    {
                                        <tr>
                                            <td align="center">
                                                <input type="hidden" name="hide_goods_id" value="@item.id" />
                                                <input type="text" name="spec_goods_no" class="td-input" value="@item.goods_no" />
                                            </td>
                                            <td align="center"><input type="text" name="spec_market_price" maxlength="10" class="td-input" value="@item.market_price" onkeydown="return checkForFloat(this,event);" onblur="countMarketPrice(this);" /></td>
                                            <td align="center"><input type="text" name="spec_sell_price" maxlength="10" class="td-input" value="@item.sell_price" onkeydown="return checkForFloat(this,event);" onblur="countSellPrice(this);" /></td>
                                            <td align="center"><input type="text" name="spec_pv_price" maxlength="10" class="td-input" value="@item.pv_price" onkeydown="return checkForFloat(this,event);" onblur="countPVPrice(this);" /></td>
                                            <td align="center"><input type="text" name="spec_stock_quantity" maxlength="10" class="td-input" value="@item.stock_quantity" onkeydown="return checkNumber(event);" onblur="countStockQuantity(this);" /></td>
                                            <td style="white-space:inherit;word-break:break-all;">
                                                <input type="hidden" name="hide_spec_ids" value="@item.spec_ids" />
                                                <input type="hidden" name="hide_spec_text" value="@item.spec_text" />
                                                <p>@item.spec_text</p>
                                            </td>
                                            <td align="center">
                                                <input name="hide_group_price" type="hidden" value='@JsonHelper.ObjectToJSON(item.group_prices)' />
                                                <a href="javascript:;" onclick="showPriceDialog(this);">设置</a>
                                            </td>
                                        </tr>

                                    }
                                }
                            </tbody>
                        </table>
                    </div>
                </dd>
            </dl>
            <!-- /商品规格-->
        }
        <dl>
            <dt>排序数字</dt>
            <dd>
                @Html.TextBox("txtSortId", m.sort_id.ToString(), new { @class = "input small", datatype = "n", sucmsg = " " })
                <span class="Validform_checktip">*数字，越小越向前</span>
            </dd>
        </dl>
        <dl>
            <dt>浏览次数</dt>
            <dd>
                @Html.TextBox("txtClick", m.click, new { @class = "input small", datatype = "n", sucmsg = " " })
                <span class="Validform_checktip">点击浏览该信息自动+1</span>
            </dd>
        </dl>
        <dl>
            <dt>发布时间</dt>
            <dd>
                @Html.TextBox("txtAddTime", m.add_time.ToString("yyyy-MM-dd HH:mm:ss"), new { @class = "input rule-date-input", onfocus = "WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})", datatype = @"/^\s*$|^\d{4}\-\d{1,2}\-\d{1,2}\s{1}(\d{1,2}:){2}\d{1,2}$/", errormsg = "请选择正确的日期", sucmsg = " " })
                <span class="Validform_checktip">不选择默认当前发布时间</span>
            </dd>
        </dl>
        @if (ViewBag.ChannelId == "2")
        {
            <dl ID="div_albums_container">
                <dt>图片相册</dt>
                <dd>
                    <div class="upload-box upload-album"></div>
                    <input type="hidden" name="hidFocusPhoto" id="hidFocusPhoto" value="@ViewBag.hidFocusPhoto" class="focus-photo" />
                    <div class="photo-list">
                        <ul>
                            @if (m.albums != null)
                            {
                                foreach (Article_albums item in m.albums)
                                {
                                    <li>
                                        <input type="hidden" name="hid_photo_name" value="@item.id|@item.original_path|@item.thumb_path" />
                                        <input type="hidden" name="hid_photo_remark" value="@item.remark" />
                                        <div class="img-box" onclick="setFocusImg(this);">
                                            <img src="@item.thumb_path" bigsrc="@item.original_path" />
                                            <span class="remark">
                                                <i>@(item.remark == "" ? "暂无描述..." : item.remark)</i>
                                            </span>
                                        </div>
                                        <a href="javascript:;" onclick="setRemark(this);">描述</a>
                                        <a href="javascript:;" onclick="delImg(this);">删除</a>
                                    </li>
                                }
                            }
                        </ul>
                    </div>
                </dd>
            </dl>
        }
    </div>
    <!-- /基本信息 -->
    <!-- 详细描述 -->
    <div class="tab-content" style="display:none">
        <dl>
            <dt>URL链接</dt>
            <dd>
                @Html.TextBox("txtLinkUrl", m.link_url, new { @class = "input normal", maxlength = "255" })
                <span class="Validform_checktip">填写后直接跳转到该网址</span>
            </dd>
        </dl>

        <!-- 信息来源 -->
                <dl ID="div_source">
                    <dt><label id="div_source_title">信息来源</label></dt>
                    <dd>
                        @Html.TextBox("field_control_source", m.source, new { @class = "input normal" })
                        <label id="div_source_tip" class="Validform_checktip">信息来源</label>
                    </dd>
                </dl>
        <!-- /信息来源 -->
        <!-- 文章作者 -->
                <dl ID="div_author">
                    <dt><label id="div_author_title">文章作者</label></dt>
                    <dd>
                        @Html.TextBox("field_control_author", m.author, new { @class = "input normal", datatype = "s0-50", sucmsg = " " })
                        <label id="div_author_tip" class="Validform_checktip">文章作者</label>
                    </dd>
                </dl>
        <!-- /文章作者 -->

        <dl>
            <dt>内容摘要</dt>
            <dd>
                @Html.TextArea("txtZhaiyao", m.zhaiyao, new { @class = "input", datatype = "*0-255", sucmsg = " " })
                <span class="Validform_checktip">不填写则自动截取内容前255字符</span>
            </dd>
        </dl>
        <dl>
            <dt>内容描述</dt>
            <dd>
                @Html.TextArea("txtContent", m.content, new { @class = "editor" })
            </dd>
        </dl>
    </div>
    <!-- /详细描述 -->
    <!-- SEO选项 -->
    <div class="tab-content" style="display:none">
        <dl>
            <dt>SEO标题</dt>
            <dd>
                @Html.TextBox("txtSeoTitle", m.seo_title, new { @class = "input normal", maxlength = "255", datatype = "*0-100", sucmsg = " " })
                <span class="Validform_checktip">255个字符以内</span>
            </dd>
        </dl>
        <dl>
            <dt>SEO关健字</dt>
            <dd>
                @Html.TextArea("txtSeoKeywords", m.seo_keywords, new { @class = "input normal", datatype = "*0-255", sucmsg = " " })
                <span class="Validform_checktip">以“,”逗号区分开，255个字符以内</span>
            </dd>
        </dl>
        <dl>
            <dt>SEO描述</dt>
            <dd>
                @Html.TextArea("txtSeoDescription", m.seo_description, new { @class = "input", datatype = "*0-255", sucmsg = " " })
                <span class="Validform_checktip">255个字符以内</span>
            </dd>
        </dl>
    </div>
    <!-- /SEO选项 -->
    <!--/内容-->
    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-wrap">
            <input type="submit" id="btnSubmit" class="btn" value="提交保存" />
            <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript:history.back(-1);" />
        </div>
    </div>
    <!--/工具栏-->
</form>
